window.onload = function () {
    let titleEle = document.getElementById('title')
    let idEle = document.getElementById('id')
    let authorEle = document.getElementById('author')
    let contentEle = document.getElementById('content')
    let statusEle = document.getElementsByName('status');
    let selectEle = document.getElementById('cat_id');
    let options = document.querySelectorAll('#cat_id option');
    let imgEle = document.getElementById('img');
    let oldImgEle = document.getElementById('oldImg');
    let fengmian = document.getElementById('fengmian');
    
    fengmian.onchange = function(){
        let file = this.files[0];
        let fileReader = new FileReader();
        fileReader.readAsDataURL(file);
        fileReader.onload =function(){
            imgEle.src = this.result;
        }
    }

    let id = "{{ article.id }}";
    let status = "{{ article.status }}";
    let cat_id = "{{ article.cat_id }}";
    
    let input = [...statusEle].find(item => item.value == status)
    input.checked = true;
    selectEle.value = cat_id;
    idEle.value = id;
    titleEle.value = "{{ article.title }}"
    authorEle.value = "{{ article.author }}"
    contentEle.value = "{{ article.content }}"
    oldImgEle.value = "{{ article.img }}"
    imgEle.src ="/{{ article.img}}"
    
    // $('#title').val('{{ article.title }}');
}

